//
// Created by 张亦乐 on 2018/9/18.
//
#include "ArenaSrv.hpp"
#include "hybrid/google/ProtoCallback.hpp"

#include "ArenaRoom.hpp"
#include "Baller.hpp"

#include "proto/MsgLogin.pb.h"
using namespace ProtoMsg;

TcpConnectorPtr DoNothing(TcpConnectorPtr conn)
{
    return conn;
}

#define HANDLE_PROTO_MSG(REQUEST)\
void Handle##REQUEST(TcpConnectorPtr conn,const REQUEST& request);\
template<>\
ProtoCallbackT<REQUEST> ProtoCallbackT<REQUEST>::Instance(Handle##REQUEST,DoNothing);\
void Handle##REQUEST(TcpConnectorPtr conn,const REQUEST& request)\

#define REPLY_PROTO_MSG(REQUEST,RESPONSE)\
uint32_t Reply##REQUEST(TcpConnectorPtr conn,const REQUEST& request,RESPONSE& response);\
template<>\
ProtoCallbackReply<REQUEST,RESPONSE> ProtoCallbackReply<REQUEST,RESPONSE>::Instance(Reply##REQUEST,DoNothing);\
uint32_t Reply##REQUEST(TcpConnectorPtr conn,const REQUEST& request,RESPONSE& response)

int main()
{
    Reactor reactor;
    ArenaSrv server("ArenaSrv",reactor);
    server.Loop();
    return 0;
}

REPLY_PROTO_MSG(UserLoginCS,UserLoginSC)
{
	auto ballerPtr = BallerMgr::GetInstance().CreateBaller(conn,request.username(),request.color());
	conn->SetTie(ballerPtr);
	UserInfo* userInfo = response.mutable_userinfo();
	userInfo->set_userid(ballerPtr->ID());
	userInfo->set_username(ballerPtr->Name());
	userInfo->set_roomid(-1);
    return 0;
}
